﻿<Window x:Class="TransportAnalizer_2._0.Views.NodeView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        d:DataContext="{d:DesignInstance viewModels:NodeViewModel}"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:data="clr-namespace:TransportAnalizer_2._0.Model"
        xmlns:local="clr-namespace:TransportAnalizer_2._0.Views"
        xmlns:viewModels="clr-namespace:TransportAnalizer_2._0.ViewModels"
        xmlns:helpClasses="clr-namespace:TransportAnalizer.HelpClasses;assembly=TransportAnalizer.HelpClasses"
        xmlns:ACB="clr-namespace:AttachedCommandBehavior;assembly=AttachedCommandBehavior"
        Title="MainWindow" Height="350" Width="887"
        ACB:CommandBehavior.Event="Loaded"
        ACB:CommandBehavior.Command="{Binding GetNodeListCommand}">
    <Window.Resources>
        <BooleanToVisibilityConverter x:Key="VisibilityConverter"/>
        <local:GeographyValueConverter x:Key="GeoConverter"/>
        <Style TargetType="Label">
            <Setter Property="Padding" Value="0"/>
        </Style>
    </Window.Resources>

    <DockPanel Margin="30">
        <DockPanel DockPanel.Dock="Left" Width="500" Margin="0,0,32,0">
            <TextBlock DockPanel.Dock="Top">
                <Hyperlink Command="{Binding AddCommand}">Добавить узлы</Hyperlink>
                <Hyperlink Command="{Binding GetNodeListCommand}">Обновить список</Hyperlink>
            </TextBlock>
            <ListBox ItemsSource="{Binding Nodes}" SelectedItem="{Binding SelectedNode}">
                <ListBox.Resources>
                    <DataTemplate DataType="{x:Type data:Node}">
                        <TextBlock>
                            <TextBlock.Text>
                                <MultiBinding StringFormat="{} {0} ({1} , {2}) - {3}">
                                    <Binding Path="Id"/>
                                    <Binding Path="Location.Longitude"/>
                                    <Binding Path="Location.Latitude"/>
                                    <Binding Path="NodeType.Name"/>
                                </MultiBinding>
                            </TextBlock.Text>
                        </TextBlock>
                    </DataTemplate>
                </ListBox.Resources>
            </ListBox>
        </DockPanel>
        <StackPanel DockPanel.Dock="Right" Visibility="{Binding CanModify, Converter={StaticResource VisibilityConverter}}">
            <Label>Координаты (долгота , широта)</Label>
            <TextBox Text="{Binding SelectedNode.Location, 
                                    ValidatesOnDataErrors=True, 
                                    UpdateSourceTrigger=PropertyChanged,
                                    Converter={StaticResource GeoConverter}}"/>

            <Label>Тип узла</Label>

            <ComboBox ItemsSource="{Binding NodeTypeViewModel.NodeTypes}" 
                      SelectedItem="{Binding SelectedNode.NodeType, 
                                    ValidatesOnDataErrors=True, 
                                    UpdateSourceTrigger=PropertyChanged
                                    }"
                      ACB:CommandBehavior.Event="Loaded"
                      ACB:CommandBehavior.Command="{Binding NodeTypeViewModel.GetNodeTypeListCommand}">
                <ComboBox.ItemTemplate>
                    <DataTemplate DataType="{x:Type data:NodeType}">
                        <TextBlock>
                            <TextBlock.Text>
                                <Binding Path="Name"/>
                            </TextBlock.Text>
                            <TextBlock.ToolTip>
                                <Binding Path="Description"/>
                            </TextBlock.ToolTip>
                        </TextBlock>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <TextBlock>
                <Hyperlink Command="{Binding OpenNodeTypeViewCommand}">Редактировать типы узла</Hyperlink>
                <Hyperlink Command="{Binding UpdateCommand}">Сохранить</Hyperlink>
                <Hyperlink Command="{Binding DeleteCommand}">Удалить</Hyperlink>
            </TextBlock>
        </StackPanel>
    </DockPanel>
</Window>
